#include "ScaleTo.h"
#include "T_Node.h"
#include "T_Scene.h"

ScaleTo *ScaleTo::create(float scaleX,float scaleY,float duration){
	ScaleTo *ret=new ScaleTo();
	ret->m_ScaleX=scaleX;
	ret->m_ScaleY=scaleY;
	ret->setDuration(duration);
	return ret;
}

bool ScaleTo::init(T_Node *node){
	if(ActionInterval::init(node)){
		m_DeltaX=(m_ScaleX-node->getScaleX())/m_Duration;
		m_DeltaY=(m_ScaleY-node->getScaleY())/m_Duration;
		return true;
	}
	return false;
}
void ScaleTo::startWithTarget(T_Node *node){
	if(init(node)){
		T_Scene *scene=node->getScene();
		if(NULL==scene)return;
		scene->getActionPool().removeAll(node,getActionType());
		scene->getActionPool().add(this);
	}
}

void ScaleTo::update(int dt){
	ActionInterval::update(dt);
	float scaleX=m_Target->getScaleX();
	float scaleY=m_Target->getScaleY();
	scaleX+=m_DeltaX*dt;
	scaleY+=m_DeltaY*dt;
	m_Target->setScaleX(scaleX);
	m_Target->setScaleY(scaleY);
}